package cn.juque.jdfsystem.controller.message;

import cn.juque.common.base.BaseRequestVO;
import cn.juque.common.base.BaseResponseVO;
import cn.juque.common.constants.MessageEnum;
import cn.juque.common.disruptor.DisruptorHandler;
import cn.juque.jdfsystem.controller.BaseController;
import cn.juque.jdfsystem.disruptor.bo.RegisterUpdateBodyBO;
import cn.juque.jdfsystem.disruptor.event.RegisterUpdateDisruptorEventServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>RegisterMessageController</li>
 * </ul>
 * @date 2023-01-11 15:32:17
 **/
@Slf4j
@Controller
@RequestMapping("/jdf/message/register")
public class RegisterMessageController extends BaseController {

    @Resource
    private DisruptorHandler disruptorHandler;

    /**
     * 查询
     *
     * @param request BaseRequestVO
     * @return BaseResponseVO
     */
    @PostMapping(value = "/change")
    @ResponseBody
    public BaseResponseVO<Boolean> change(@RequestBody BaseRequestVO<String> request) {
        this.validatorUtil.checkNotNull(request);
        RegisterUpdateBodyBO bodyBO = new RegisterUpdateBodyBO();
        bodyBO.setBusinessEventService(RegisterUpdateDisruptorEventServiceImpl.BEAN);
        bodyBO.setSendNode(request.getParam());
        this.disruptorHandler.publish(bodyBO);
        return new BaseResponseVO<>(MessageEnum.OK, true);
    }

    /**
     * 查询
     *
     * @return BaseResponseVO
     */
    @PostMapping(value = "/check")
    @ResponseBody
    public BaseResponseVO<Integer> check(@RequestBody BaseRequestVO<Integer> requestVO) {
        return new BaseResponseVO<>(MessageEnum.OK, requestVO.getParam());
    }
}
